package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.itheima.dao.LinkManDao;
import com.itheima.domain.LinkMan;
import com.itheima.service.LinkManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ClassName:LinkManServiceImpl
 * Package:com.itheima.service.impl
 * Description:
 * Date:2020/3/19 21:10
 * User: snow
 */
@Service
@Transactional
public class LinkManServiceImpl implements LinkManService {

	@Autowired
	private LinkManDao linkManDao;

	@Override
	public List<LinkMan> findAll() throws Exception {
		return linkManDao.findAll();
	}

	@Override
	public List<LinkMan> findAll(int page,int size) throws Exception {
		/**
		 * //参数配置
		 * pageNum 页码值   pageSize  每页最大值
		 */
		PageHelper.startPage(page,size);
		return linkManDao.findAll();
	}

	@Override
	public void save(LinkMan linkMan) throws Exception {
		linkManDao.save(linkMan);
	}

	@Override
	public void delete(String id) throws Exception {
		linkManDao.delete(id);
	}

	@Override
	public List<LinkMan> findSome(String linkmanName, String linkmanGender,int page,int size) throws Exception {
		LinkMan linkMan = new LinkMan();
		if (linkmanName != null){
			linkMan.setLinkmanName(linkmanName);
		}
		if(linkmanGender != null){
			linkMan.setLinkmanGender(linkmanGender);
		}
		/**
		 * //参数配置
		 * pageNum 页码值   pageSize  每页最大值
		 */
		PageHelper.startPage(page,size);
		return linkManDao.findSome(linkMan);
	}

	@Override
	public LinkMan findById(String id) throws Exception {
		return linkManDao.findById(id);
	}

	/**
	 * 更改联系人信息
	 * @param linkMan
	 * @throws Exception
	 */
	@Override
	public void update(LinkMan linkMan) throws Exception {
		linkManDao.update(linkMan);
	}

	@Override
	public List<LinkMan> findLinkManByCustomerId(String id) throws Exception{
		return linkManDao.findLinkManByCustomerId(id);
	}
}
